﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace SmallTfs
{
    /// <summary>
    /// Interaction logic for TaskGrid.xaml
    /// </summary>
    public partial class TaskGrid : UserControl
    {
        ObservableCollection<TaskItem> current = null;
        public TaskGrid(List<TaskItem> datasource)
        {
            InitializeComponent();
            current = datasource.Distinct().OrderBy(x => x.Id).ToList().ToObservableCollection();

            dtShangeSet.ItemsSource = current;
        }

        public TaskGrid()
        {
            InitializeComponent();
            //current = datasource.Distinct().OrderBy(x => x.Id).ToList().ToObservableCollection();
        }

        public void SetDataSource(List<TaskItem> datasource)
        {
            current = datasource.Distinct().OrderBy(x => x.Id).ToList().ToObservableCollection();
            dtShangeSet.ItemsSource = current;
        }
        
        private void btnSelectAll_Click(object sender, RoutedEventArgs e)
        {
            if(current == null)
                return;

            foreach (var t in current)
                t.Selected = true;
        }

        private void btnUnselectAll_Click(object sender, RoutedEventArgs e)
        {
            if (current == null)
                return;

            foreach (var t in current)
                t.Selected = false;

        }
    }
}
